{% extends "layouts/application.html" %}
{% block content %}

<script type="text/javascript">
	function pageselectCallback(page_id, jq){
		//alert(page_id)
		window.location.href="?page="+(page_id+1);
    }
    $(document).ready(function(){
		// Create pagination element
		$("#img_upload").hide();
        $("#Pagination").pagination({{objects.paginator.count}}, {
			num_edge_entries: 2,
			num_display_entries: 8,
			current_page:({{objects.number}}-1),
            callback: pageselectCallback
        });

	     var options = {
	     	type:'post',
	       	beforeSubmit:  showRequest,  // pre-submit callback
	       	success:       showResponse  // post-submit callback
	   	 };
    	 $('#upload_form').ajaxForm(options);
     });
		function showRequest(formData, jqForm, options) {
			var title = $('input[@name=name]').fieldValue();
			var about = $('textarea[@name=about]').fieldValue();
			var file = $('input[@name=filepath]').fieldValue();
			var image = $('input[@name=filepic]').fieldValue();
			if(!title[0]){
				alert("文件标题不能为空！");
				return false
			}
			if(!about[0]){
				alert("文件说明不能为空！");
				return false
			}
			if(!file[0]){
				alert("上传附件不能为空！");
				return false
			}
			if(image[0]){
				var type = image[0].substring(image[0].indexOf('.'),image[0].length)
				if(type!=".jpg"&&type!=".jpeg"&&type!=".gif"&&type!=".bmp"&&type!=".png"){
					alert("对不起,您上传的图片格式不正确");
					return false
				}
			}
			$("#img_upload").show();
		    return true;
		 }
		function showResponse(responseText, statusText)  {
			if(statusText="success"){
				$("#img_upload").hide();
				alert("文件上传完成");
				location.reload();
			}else{
				$("#img_upload").hide();
				alert("文件上传失败");
			}
		}
    function to_thumb(id){
    	window.location.href="../show_files_pic/ca_"+id+"type_1";
    }
</script>
<div align="center">
  <DIV class=boxright>
    <DIV class=bltop2>
      <div align="left">&nbsp;&nbsp;&nbsp;
        <strong>
          当前位置：&nbsp;&nbsp;
          <a href="/{%site_root%}/resource/show_resource/">资料库</a>
          <img src="/site_media/images/zd_arrow.gif">&nbsp;&nbsp;
          <a href="/{%site_root%}/resource/show_leveltwo_resource/{{obj.parentId.id}}">{{obj.parentId.name}}</a>
          <img src="/site_media/images/zd_arrow.gif">&nbsp;&nbsp;
          <a href="{{obj.get_files_url}}">{{obj}}</a>
        </strong>
      </div>
    </DIV>
        <div id="upfile_div">
        <form id="upload_form" action="" enctype="multipart/form-data" method="post">
          <TABLE id=tblSearch  cellSpacing=0 cellPadding=4  width="100%" border=0>
            <TBODY>
              <TR>
                <TD class=rep_li_c2 width="10%" >前缀一</TD>
                <TD class=rep_li_c2 width="10%" ALIGN="left">
                  {{form.prefix_one}}{{form.prefix_one.errors}}
                </TD>
                <TD class=rep_li_c2 width="10%">前缀二</TD>
                <TD class=rep_li_c2 width="10%" ALIGN="left">
                  {{form.prefix_two}}{{form.prefix_two.errors}}
                </TD>
                <TD class=rep_li_c2 width="10%">前缀三</TD>
                <TD class=rep_li_c2 width="18%" ALIGN="left">
                  {{form.prefix_three}}{{form.prefix_three.errors}}
                </TD>
              </TR>
              <TR>
                <TD class=rep_li_c2 width="18%">文件标题</TD>
                <TD class=rep_li_c2  COLSPAN="5" ALIGN="left">
                {{form.name}}{{form.name.errors}}
                </TD>
              </TR>
              <TR>
                <TD class=rep_li_c2 width="18%">文件说明</TD>
                <TD class=rep_li_c2  COLSPAN="5" ALIGN="left">
                {{form.about}}{{form.about.errors}}
                </TD>
              </TR>
              <TR>
                <TD class=rep_li_c2 width="18%">资料文件</TD>
                <TD class=rep_li_c2  COLSPAN="5" ALIGN="left">
                  {{form.filepath}}<span style="color:red;">{{form.filepath.errors}}</span>
                  <span class="annotation">(选择您要上传的文件,若提示该文件格式不允许上传,请压缩成*.zip或*.rar后上传)</span>
                </TD>
              </TR>
              <TR>
                <TD class=rep_li_c2 width="18%">图片预览</TD>
                <TD class=rep_li_c2  COLSPAN="5" ALIGN="left">
                  {{form.filepic}}<span style="color:red;">{{form.filepic.errors}}</span>
                  <span class="annotation">(可选项,您可对非图片资料文件上传一张预览图片,以方便查看)</span>
                </TD>
              </TR>
              <TR>
                <TD class=rep_li_c2 colSpan=6>
                  <table width="100%">
                    <tr>
                      <td width="90%" align="center">
                      <INPUT ONCLICK="return file_type_filter();" onMouseOver="this.className='submit2'" onMouseOut="this.className='submit'" class=submit id="" type=submit value=上传 name="">
                      <INPUT onMouseOver="this.className='reset2'" onMouseOut="this.className='reset'" id="reset_load" class="reset"  type="reset" value=取消>
                      </td>
                      <td><input id="chkThumb" type="checkbox" alt="只显示有缩略图的文件" onclick="to_thumb({{obj.id}})">缩略图查看</td>
                      </tr>
                 </table>
                </TD>
              </TR>
            </TBODY>
          </TABLE>
        </form>
        </div>
        <img id="img_upload" src="/site_media/images/uploading.gif" >
    <DIV class=c_box>
    <form id="file_modif" action="" method="post">
      <DIV class="rep_left">
          <TABLE id=show_tab class=tatop7px cellSpacing=0 cellPadding=4 width="100%" border=0>
            <THEAD>
              <TR ALIGN="center">
              	<TH><INPUT id="chkAll" onclick="title_check('chkAll','chkID[]')"  type="checkbox" value=checkbox></TH>
                <TH class=rep_li_c width="10%"><STRONG>前缀一</STRONG></TH>
                <TH class=rep_li_c width="16%"><STRONG>前缀二</STRONG></TH>
                <TH class=rep_li_c width="12%"><STRONG>地市</STRONG></TH>
                <TH class=rep_li_c width="17%"><STRONG>文件名</STRONG></TH>
                <TH class=rep_li_c width="1%"><STRONG>&nbsp;</STRONG></TH>
                <TH class=rep_li_c width="10%"><STRONG>上传人</STRONG></TH>
                <TH class=rep_li_c width="10%"><STRONG>大小</STRONG></TH>
                <TH class=rep_li_c width="18%"><STRONG>创建日期</STRONG></TH>
                <TH class=rep_li_c width="6%"><STRONG>&nbsp;</STRONG></TH>
              </TR>
            </THEAD>
            <TBODY>
              {% if objects.object_list %}
              {% for file in objects.object_list %}
                <TR id="tr_{{file.id}}" style="TEXT-DECORATION: none" onMouseOver="this.style.backgroundColor='#EFF8FF'" onmouseout="this.style.backgroundColor=''">
				  <TD class=rtdw2>
                    <INPUT onclick="rows_check('chkAll','chkID[]')" type=checkbox value="{{file.id}}" name="chkID[]">
                  </TD>
				  <TD class=rep_li_td_bt>{{file.prefix_one}}</TD>
				  <TD class=rep_li_td_bt>{{file.prefix_two}}</TD>
				  <TD class=rep_li_td_bt>{{file.prefix_three}}</TD>
                  <TD class=rep_li_td_bt ALIGN="center"><a href="{{file.getFile}}">{{file.name}}</a> </TD>
                  <td>
                  {% if file.filepic%}
                  <a href="{{file.getImgPath}}" class="imagesview" ><img border="0" src="/site_media/images/picture1.png" height="16" width="16" alt="预览"></a>
                  {% endif %}
                  </td>
                  <TD class=rep_li_td_bt>{{file.user.username}}</TD>
                  <TD class=rep_li_td_bt>{{file.size|filesizeformat}}</TD>
                  <TD class=rep_li_td_bt>{{file.datetime|date:"Y年n月j日h点i分"}}</TD>
                  <TD class=rep_li_td_bt>
                    <a href="{{file.getFilePath}}" target="_blank"><img src="/site_media/images/down_icon.png" border="0" height="16" width="16" alt="下载"></a>
                  </TD>
                </TR>
              {% endfor %}
              {% endif %}
            </TBODY>
          </TABLE>
          <TABLE cellSpacing=0 cellPadding=4 width="100%" border=0>
            <TBODY>
              <TR vAlign=top>
              <TR vAlign=top ALIGN="left">
                <TD>
                  <INPUT onclick="return check_select_one('chkAll','chkID[]','/{%site_root%}/manage/edit_file/')"
                         name="button" class="button" id="edit"  type="button" value="编辑文件">
                  <INPUT ONCLICK="return check_select('chkID[]','file_modif','/{%site_root%}/manage/trash_put/{{obj.id}}');"
                         name="button" class="button" id="delete"   type="submit" value="放入回收站">
                  <INPUT ONCLICK="return check_select('chkID[]','file_modif','/{%site_root%}/manage/trash_del/{{obj.id}}');"
                         name="button" class="button" id="destroy"  type="submit" value="彻底删除">

                </TD>
                <td><div id="Pagination" class="pagination"></td>
              </TR>
            </TBODY>
          </TABLE>
		</form>
      </DIV>
    </DIV>
  </DIV>
  <div>
  </div>
</div>
{% endblock %}
